package com.yjz.jvm.juc.yield;

import lombok.extern.slf4j.Slf4j;

/**
 * @author :yuanJinZhong
 * @description:线程方法yield 线程让步(让出cpu时间片 ， 不让出同步监视器)
 * @date :2018/7/11-18:20
 */
@Slf4j
public class Yield_Learn {

  private static Object lock = new Object();

  private static Thread t1 = new Thread(() -> {
    log.info("1");
    log.info("2");
    log.info("3");
//		try {
    Thread.yield();
//			Thread.sleep(10000);
//		} catch (InterruptedException e) {
//			e.printStackTrace();
//		}
//		log.info("线程1 状态"+String.valueOf(Thread.currentThread().getState()));
    log.info("4");
    log.info("5");
  }, "线程1");

  private static Thread t2 = new Thread(() -> {
    log.info(Thread.currentThread().getName() + "欢快的执行");
  }, "线程2");


  public static void main(String[] args) throws InterruptedException {
    t1.start();
    t2.start();

  }
}
